/*
 * Copyright (c) 2005-2006 IntellSoft All Rights Reserved.
 */
package com.feyaSoft.home.base;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;

/**
 * This class is used to set the global session information, such as user id,
 * name, lang etc. Any information thay you want to put in the global data
 * should be set in here.
 * 
 * @author fzhuang
 * @Date Jan 1, 2005
 */
public class GlobalSessionData {

	private String client = "careConn";
	private Long userId = null;
	private String userName = null;
	private Long topLocationId;
	private String userLanguage = null;
	private String fullname = null;
	private Set roles = null;
	private String topRole = "student";
	private Long topRoleId;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * The constructor of class GlobalSessionData.java
	 */
	public GlobalSessionData() {
		// TODO Auto-generated constructor stub
	}

	
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	/**
	 * @return Returns the fullname.
	 */
	public String getFullname() {
		return fullname;
	}

	/**
	 * @param fullname
	 *            The fullname to set.
	 */
	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	public Long getTopLocationId() {
		return topLocationId;
	}

	public void setTopLocationId(Long topLocationId) {
		this.topLocationId = topLocationId;
	}

	/**
	 * @return Returns the roles.
	 */
	public Set getRoles() {
		return roles;
	}

	/**
	 * @param roles
	 *            The roles to set.
	 */
	public void setRoles(Set roles) {
		this.roles = roles;
	}

	/**
	 * Gets the userLanguage attribute of the GlobalSessionData object
	 * 
	 * @return The userLanguage value
	 */
	public String getUserLanguage() {
		return userLanguage;
	}

	/**
	 * Sets the userLanguage attribute of the GlobalSessionData object
	 * 
	 * @param userLanguage
	 *            The new userLanguage value
	 */
	public void setUserLanguage(String userLanguage) {
		this.userLanguage = userLanguage;
	}

	public String getTopRole() {
		return topRole;
	}

	public void setTopRole(String topRole) {
		this.topRole = topRole;
	}

	public Long getTopRoleId() {
		return topRoleId;
	}

	public void setTopRoleId(Long topRoleId) {
		this.topRoleId = topRoleId;
	}

	public String getClient() {
		return client;
	}

	public void setClient(String client) {
		this.client = client;
	}

	/**
	 * This method is used to get the system data based request
	 * 
	 * @param request
	 *            Description of the Parameter
	 * @return Description of the Return Value
	 */
	public static GlobalSessionData getSessionData(HttpServletRequest request) {
		GlobalSessionData globalSD = (GlobalSessionData) request.getSession()
				.getAttribute(HomeKey.SESSION_KEY);

		return globalSD;
	}

	/**
	 * This method is used to get the system data based on HttpSessionEvent evt
	 * 
	 * @param request
	 *            Description of the Parameter
	 * @return Description of the Return Value
	 */
	public static GlobalSessionData getSessionDataByEvent(HttpSessionEvent evt) {
		GlobalSessionData globalSD = (GlobalSessionData) evt.getSession()
				.getAttribute(HomeKey.SESSION_KEY);

		return globalSD;
	}

	/**
	 * This method saves the object in the request (session).
	 * 
	 * @param request
	 *            Description of the Parameter
	 * @param gsd
	 *            Description of the Parameter
	 */
	public static void save(HttpServletRequest request,
			GlobalSessionData globalSD) {
		HttpSession session = request.getSession();
		session.setAttribute(HomeKey.SESSION_KEY, globalSD);
	}

}
